<?php
/**
 * 
 * Modelo de gestion de control interno
 * @author Natanael
 * 
 */
class Mcihistorico extends Model{

      private $_nameTable = "CI_historico";
      
      public function __construct()
      {
      	 parent::Model();
         $this->load->database(); 
      }
      
      public function loadGestion($start = false, $offset = false, $sortname = false, $sortorder = false)
      {
         if($offset != false)
		      $this->db->limit($offset, $start);
  
		 if($sortname != false && $sortorder != false){ 
				  $this->db->order_by($sortname, $sortorder);
		  }else{
			    $this->db->order_by('idRegistro', 'ASC');
	     }	  
				  
		  $result = $this->db->get_where($this->_nameTable);
	
		   return $this->GetArrayFromQueryResult($result);
			
      }
         
       public function LoadGestionById($idStatus) 
	   {
		   $qresult = $this->db->get_where($this->_nameTable, array('idCompania' => $idStatus));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
           
		   return new CI_historico($qresult->row());
	    }
	    
      public function LoadGestionValidar($compani, $etapa) 
	   {
		   $qresult = $this->db->get_where($this->_nameTable, array('idCompania' => $compani,
		                                                              'idEstapa'=>$etapa));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
            
		   return new CI_historico($qresult->row());
	    }  
         
         public function GetArrayFromQueryResult($result) 
	     {
			if ($result->num_rows() == 0)
				return false;
	
			$estatus_arr = array();
	
			foreach ($result->result() as $record) {
				$estatus_arr[] = new CI_historico($record);
			}
	
			return $estatus_arr;
         }
         
        public function crear($data)
        {
           if ($this->db->insert($this->_nameTable,$data)) {
           	  return true;
           }
           
            return false;
        }
        
        public function edit($data, $id)
        {
           if ($this->db->update($this->_nameTable,$data,array('idCompania'=>$id))) {
           	  return true;
           }
           
            return false;
        }
        
        public function delete($id)
        {
             if ($this->db->delete($this->_nameTable,array('idRegistro'=>$id))) {
           	    return true;
             }
           
              return false;
        }

}

class CI_historico{
          
	     private $_idRegistro = 0;
	     private $_idCompania = 0;
	     private $_idEstapa = 0;
	     private $_idEstatus = 0;
	     private $_nota = "";
	     private $_fechaSystem = "";
	     private $_fechaContacto = "";
	     private $_fechaRegistro = "";
	    
	     public function __construct($ojt)
	     {
	           $this->setIdRegistro($ojt->idRegistro);
	           $this->setIdCompania($ojt->idCompania);
	           $this->setIdEstapa($ojt->idEstapa);
	           $this->setIdEstatus($ojt->idEstatus);
	           $this->setNota($ojt->nota);
	           $this->setFechaSystem($ojt->fechaSystem);
	           $this->setFechaContacto($ojt->fechaContacto);
	           $this->setFechaRegistro($ojt->fechaRegistro);
	     } 
	     
	     public function getIdRegistro(){
	        return $this->_idRegistro;
	     }
	     
         public function setIdRegistro($ojt){
	        $this->_idRegistro = $ojt;
	     }
	     
	     public function getIdCompania()
	     {
	        return $this->_idCompania;
	     }
	     
         public function setIdCompania($ojt)
	     {
	        $this->_idCompania = $ojt;
	     }

         public function getIdEstapa()
	     {
	        return $this->_idEstapa;
	     }
	     
         public function setIdEstapa($ojt)
	     {
	        $this->_idEstapa = $ojt;
	     }

         public function getIdEstatus()
	     {
	        return $this->_idEstatus;
	     }
	     
         public function setIdEstatus($ojt)
	     {
	        $this->_idEstatus = $ojt;
	     }

         public function getNota()
	     {
	        return $this->_nota;
	     }
	     
         public function setNota($ojt)
	     {
	        $this->_nota = $ojt;
	     }
         
         public function getFechaSystem()
	     {
	        return $this->_fechaSystem;
	     }
	     
         public function setFechaSystem($ojt)
	     {
	        $this->_fechaSystem = $ojt;
	     }

         public function getFechaContacto()
	     {
	        return $this->_fechaContacto;
	     }
	     
         public function setFechaContacto($ojt)
	     {
	        $this->_fechaContacto = $ojt;
	     }

         public function getFechaRegistro()
	     {
	        return $this->_fechaRegistro;
	     }
	     
         public function setFechaRegistro($ojt)
	     {
	        $this->_fechaRegistro = $ojt;
	     }
}